<?php
/**
 * Commodity Controller
 * 
 * @author Nguyen Hai Ha
 * @version 1.0
 */

class Administrator_CommodityController extends Zend_Controller_Action {
	protected $_baseUrl;
	protected $_contextPath;
	protected $_utilities;
	protected $_errors;
	protected $_auth;
	
	public function init() {
		$this->_baseUrl = $this->_request->getBaseURL ();
		$this->_contextPath = "administrator/commodity";
		
		$this->view->assign ( "baseUrl", $this->_baseUrl );
		$this->view->assign ( "contextPath", $this->_contextPath );
		
		$this->_utilities = new Utilities ( );
		$this->view->assign ( "utilities", $this->_utilities );
		
		$this->_auth = Zend_Auth::getInstance()->getIdentity();
		
		$this->_errors = array ();
	}
	
	public function indexAction() {
		
	}

	public function postedAction() {
		$comModel = new CommodityModel ( );
		
		/** Begin: render script for paging. */
		$paging = new Paging ( );
		/** 
		 * Get item on page.
		 * Get total page.
		 */
		$itemPerPage = Constant::COMMODITY_LIST_ITEM;
		$totalRecords = $comModel->getTotalRecords ( );
		$currentPages = ( int ) $this->_request->getParam ( 'page' );
		if ($currentPages == 0)
			$currentPages = 1;
		/** 
		 * Set url for paging.	
		 * Render paging for page.	
		 */
		$url = $this->_baseUrl . "/" . $this->_contextPath . "/posted";
		$page = $paging->doPaging ( $totalRecords, $url, $currentPages, $itemPerPage );
		$page_title = $paging->doPageSeparator ( $totalRecords, $currentPages, $itemPerPage );
		/** Set param for view. */
		$this->view->assign ( "page", $page );
		$this->view->assign ( "page_title", $page_title );
		$this->view->assign ( "currentPage", $currentPages );
		/** End: render script for paging. */
				
		$commodities = $comModel->getAllCommodity ( $currentPages, $itemPerPage );

		$this->view->assign ( "commodities", $commodities );
		$this->render ( "posted" );
	}
	
	public function bannedAction() {
		
	}
	
	public function violateAction() {
		
	}
}
